<?php
include '../comm/config.php';
$link = mysql_connect($dbserver, $dbuser, $dbpass);
if (!$link) {
	die(ERR_DB);
}
else
{	
    mysql_select_db($dbname);
    mysql_query("set names utf8");
//*********************提现记录**********************
$s="SELECT * FROM `".$BIAOTOU."tixian`  order by `Id` desc";
$query=mysql_query($s);
$tixian =  array();
while($arr = mysql_fetch_array($query)){
	$tixian[]=$arr;
	}

}
if(count($tixian)==0){
$tixian = array (
	array (
		ddusername => 'etrty',
		txje => 21.6
	),
	array (
		ddusername => 'fsdfs',
		txje => 26.8
	),
	array (
		ddusername => 'ghjgj',
		txje => 35.4
	),
	array (
		ddusername => 'hgjh',
		txje => 54
	),
	array (
		ddusername => 'iouio',
		txje => 30.4
	)
);
}
$smarty->assign('tixian',$tixian);
//*****************************文章系统*********************************
	function check_atypeid($atypeid){
		global $BIAOTOU;
		$sql="select typename from ".$BIAOTOU."ttype where typeautoid='$atypeid'";
		$query=mysql_query($sql);
		while($row=mysql_fetch_array($query)){
			$typename=$row['typename'];
			}
			return $typename;
		}


function utf8Substr($str,$from,$len) { 
return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'. 
'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', 
'$1',$str); 
}

	function articleList($aType,$aLNum,$aTNum,$aSort) {
	global $BIAOTOU;
	$articleList = '';
	switch ($aSort) {
		case "2" :
			$aSort = "apv desc";
			break;
		case "1" :
			$aSort = "aid desc";
			break;
		default :
			$aSort = "atop desc, aid desc";
			break;
	}
	$aWhere = " where atypeid=" . $aType;
	if ($aType == 0) {
		$aWhere = "";
	}
	$query = "select aid,atypeid,atitle ,adate  from " . $BIAOTOU . "article" . $aWhere . " order by " . $aSort . " limit 0," . $aLNum . "";
	$result = mysql_query($query);
	$arr = array ();
	$i=0;
	while ($row = mysql_fetch_array($result)) {
		$arr[$i]['aid'] = $row['aid'];
		$arr[$i]['atypeid'] = $row['atypeid'];
		$arr[$i]['atypename'] = check_atypeid($row['atypeid']);
		$arr[$i]['atitle'] = utf8Substr($row['atitle'],0,$aTNum);
		$arr[$i]['adate'] = $row['adate'];
		$i++;
	}
	return $arr;
}
$arlist=articleList(0,10,30,4);//调用全部文章，10条，每条最多30个字，按照置顶排列
$arlist_2=articleList(2,5,30,1);//调用公告文章，6条，每条最多30个字，按照时间排列
$arlist_3=articleList(3,3,30,1);//调用购物资讯文章，6条，每条最多30个字，按照时间排列
$smarty->assign('arlist', $arlist);
$smarty->assign('arlist_news', $arlist_2);
$smarty->assign('arlist_info', $arlist_3);

mysql_close($link);
?>